home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PCMania 24
/
PCMania CD24.nrg
/
mmedia
/
music
/
mp
/
cdec.doc
next >
Wrap
Text File
|
1994-09-07
|
13KB
|
484 lines
C D E CC D E C
C Declaration to English Translator Program C Declaration to English Translator Program
for the
I.B.M PC/AT and Compatibles
by John S. Smith
c/o 'Rosemont'
Hawthorn Rd
Beaufort
Ebbw Vale
Gwent
United Kingdom
Copyright (C) 1989-90 by John S. Smith Copyright (C) 1989-90 by John S. Smith
All Rights Reserved___ ______ ________
This document last revised 21st October 1990
The CDEC diskette containing a copy of this document
is distributed under the Shareware scheme and may be
freely copied provided that none of the files
thereon are modified in any way. Printed copies of
the documentation may not be copied without the
express written permission of the author
CDEC Guide For C Programmers
1 Introduction 1 Introduction
CDEC is a program that translates declarations in
the C programming language into an English phrase.
CDEC is particularly useful for checking the meaning
of complex declarations or even not-so complex
declarations when one is unsure of the precedence of
operators. For example the difference between:
char * msg[MAX_NUM];
and
char (* msg)[MAX_NUM];
is easily and quickly found with CDEC.
Also, when trying to understand code written by
others, declarations can be a particularly
troublesome and time-consuming area. CDEC is a great
help with this sort of task.
Another useful area is when one wishes to use a
particularly complex declaration as the problem at
hand dictates it, yet how can you be sure the
declaration is right? Your compiler may compile it
ok but does the declaration mean what you want it to
mean? Just enter it to CDEC and get a second
opinion.
Declarations get even more difficult to understand
when the "far" and "near" keywords that are used
with many compilers are involved. Just what
associates with what? Well, even though "far" and
"near" are not part of the C programming language,
CDEC includes them as they are in such common usage.
There is also support for the "const" keyword.
CDEC runs on all PC compatible machines and needs no
special hardware or displays. CDEC uses a plain
scrolling display rather than pop-up menus etc to
minimise code size and thus minimises loading time
from disc. It is possible to start CDEC, check a
declaration and return to DOS before many programs
could even load! (Well I think so anyway).
A Shareware Program page 2 October, 1990
CDEC Guide For C Programmers
2 Installation and Test 2 Installation and Test
CDEC consists of just one executable file CDEC.EXE.
Copy this file to any directory in your current
path.
3 Starting CDEC 3 Starting CDEC
Type:
CDEC
or
CDEC -x
In the latter case CDEC attempts to give extra
information about certain declaration where
possible. In particular declarations involving
"const" and the common compiler extensions for
segmented addressing "far" and "near" have extra
information.
4 Usage 4 Usage
CDEC prompts for a declaration. Type in your
declaration and press the Enter or return key. CDEC
will produce an English translation on screen if
possible. If there is an error, the probable reason
is displayed followed by a new prompt for you to try
again.
The functions keys provide access to much useful
information.
The "?" key aborts the current declaration without
leaving the program.
The Esc key exits CDEC.
If you wish to save the generated output to a file,
use the DOS redirection feature and start CDEC like
this:
CDEC > myfile
CDEC will place the translated output in a file
called "myfile". This redirected output is detected
by CDEC and the output will be surrounded by
standard C comment delimiters /* comment */ so that
"myfile" can be included in your source code later
if you wish. To end this process, press Esc as
before. If any declaration is in error then the
A Shareware Program page 3 October, 1990
CDEC Guide For C Programmers
error message will always appear on the screen and
never be sent to file.
You may append a comment to any CDEC input line.
Such a comment is introduced by two slashes (//)
eg char buf[10]; // store name
This comment will also be stored in any redirected
output file.
It is possible to start CDEC with redirected output
AND with the extra information option turned on.
eg CDEC -x > myfile
In this case, any extra information goes only to
file (not to screen) but the translated output goes
to screen AND file.
CDEC will also accept a list of declarations from a
file as redirected input:
eg CDEC <list
Where the file "list" contains a list of C
declaration to be translated.
It is possible to use redirected input and output
together:
eg CDEC < list > myfile
or
CDEC -x < list > myfile
5 Commom omissions and additional information 5 Commom omissions and additional information
Failure to end the declaration with a semicolon ";".
ALL declaration require this.
CDEC can translate declaration than are beyond the
power of current compilers to accept! (At least as
far as I am aware). Such declarations are not
incorrect as such but it is just that such
declarations are maybe too expensive and/or
difficult (or unnecessary?) in computing terms to be
implemented. Maybe such declarations will never be
implemented but CDEC translates them now. This has
advantages for educational purposes at least.
Typical of such declarations are:
A Shareware Program page 4 October, 1990
CDEC Guide For C Programmers
int alpha()(); int beta()[]; int gamma[]();
Input these to CDEC to see what they mean. Pointers
to such items ARE allowed.
C declarations, particularly structures and unions
are usually written on more than one line:
eg struct tag {
int count;
char * chr;
} struct_name;
However this format is only for stylistic reasons
and such a declaration is just as valid if written
on a single line, such as
struct tag { int count; char * chr; } struct_name;
CDEC requires the single line version as translation
starts as soon as the Enter or return key is
pressed. This does not limit the length of a
declaration and a very long declaration may be
greater than one screen line -- just keep typing
when the cursor gets to the right hand side of the
screen but don't press return until the whole
declaration is entered.
CDEC translates declarations involving functions
arrays pointers "primitive" data types aggregates
data types such as struct and unions. Also there is
extended support for the "far" "near" and "const"
keywords. Note that CDEC identifies but does not
parse parameter lists for functions and behaves
similarly for struct/union member lists. Each item
of any of these lists may be input to CDEC as an
independent declaration later if further translation
is desired. It is felt that identification of these
lists is much more useful than a description of them
as they can often be very difficult to identify in a
declaration. Also the generated phrase would be
rather difficult to read which would defeat the
purpose of CDEC. CDEC also does this identification
task for initialiser lists.
Quite difficult-to-understand declarations may be
easily understood with CDEC's output. For example a
declaration such as:
struct basetype (*root (int ival, char *name)) (
char * buf[10]);
produces (actual CDEC output obtained using the
redirected output feature):
A Shareware Program page 5 October, 1990
CDEC Guide For C Programmers
/* --- CDEC TRANSLATOR ---
input received:
struct basetype (*root (int ival, char *name)) (
char * buf[10]);
cdec output:
"root": function (params: int ival, char *name)
returning pointer to
function (params: char * buf[10]) returning
structure of type basetype
*/
Be sure to read the note programmed into function
key F2
Remember CDEC handles <typedef>'s too.
6 Shareware users 6 Shareware users
Please note that pointers and redirected input
features are only supported by the registered
versions of CDEC.
A registered version can be obtained from:
John S. Smith
c/o 'Rosemont'
Hawthorn Rd
Beaufort
Ebbw Vale
Gwent
United Kingdom
The cost is 19 pounds sterling + 2 pounds p&p within
the U.K. and 3 pounds to other countries. For this
you will receive the latest version of CDEC and
discounts on any upgrades which you will be notified
about. Please state which version you have now and I
would appreciate knowing how you learned of CDEC.
Any constructive comments would also be welcomed.
Please state disc size required, 5.25" or 3.5"
7 Disclaimer 7 Disclaimer
Although considerable care has gone into the writing
and testing of this program, no responsibility is
accepted for the results obtained by using this
program. Also no guarantee or warrantee either
A Shareware Program page 6 October, 1990
CDEC Guide For C Programmers
expressed or implied is given either to the user of
the program or to any third parties. I reserve the
right to change the specification, capabilities and
charges for CDEC without notice. In other words I
cannot be bound by old advertising.
A Shareware Program page 7 October, 1990
ContentsContents
1 Introduction . . . . . . . . . . 2
2 Installation and Test . . . . . . 2
3 Starting CDEC . . . . . . . . . . 3
4 Usage . . . . . . . . . . . . . . 3
5 Commom omissions and additional
information . . . . . . . . . . . 4
6 Shareware users . . . . . . . . . 6
7 Disclaimer . . . . . . . . . . . 6
i